<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - ged.info - gil/locator.hpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../index.html">directory</a> - <a href="index.html">gil</a> - locator.hpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>ged.info</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-06-09</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">21</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">95.2 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">20</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : /*
<span class="lineNum">       2 </span>                :     Copyright 2005-2007 Adobe Systems Incorporated
<span class="lineNum">       3 </span>                :    
<span class="lineNum">       4 </span>                :     Use, modification and distribution are subject to the Boost Software License,
<span class="lineNum">       5 </span>                :     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       6 </span>                :     http://www.boost.org/LICENSE_1_0.txt).
<span class="lineNum">       7 </span>                : 
<span class="lineNum">       8 </span>                :     See http://opensource.adobe.com/gil for most recent version including documentation.
<span class="lineNum">       9 </span>                : */
<span class="lineNum">      10 </span>                : 
<span class="lineNum">      11 </span>                : /*************************************************************************************************/
<span class="lineNum">      12 </span>                : 
<span class="lineNum">      13 </span>                : #ifndef GIL_LOCATOR_H
<span class="lineNum">      14 </span>                : #define GIL_LOCATOR_H
<span class="lineNum">      15 </span>                : 
<span class="lineNum">      16 </span>                : 
<span class="lineNum">      17 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      18 </span>                : /// \file               
<span class="lineNum">      19 </span>                : /// \brief pixel 2D locator
<span class="lineNum">      20 </span>                : /// \author Lubomir Bourdev and Hailin Jin \n
<span class="lineNum">      21 </span>                : ///         Adobe Systems Incorporated
<span class="lineNum">      22 </span>                : /// \date   2005-2007 \n September 20, 2006
<span class="lineNum">      23 </span>                : ///
<span class="lineNum">      24 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      25 </span>                : 
<span class="lineNum">      26 </span>                : #include &lt;cstddef&gt;
<span class="lineNum">      27 </span>                : #include &lt;cassert&gt;
<span class="lineNum">      28 </span>                : #include &quot;pixel_iterator.hpp&quot;
<span class="lineNum">      29 </span>                : 
<span class="lineNum">      30 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      31 </span>                : ///                 Pixel 2D LOCATOR
<span class="lineNum">      32 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      33 </span>                : 
<span class="lineNum">      34 </span>                : 
<span class="lineNum">      35 </span>                : namespace boost { namespace gil {
<span class="lineNum">      36 </span>                : 
<span class="lineNum">      37 </span>                : //forward declarations
<span class="lineNum">      38 </span>                : template &lt;typename P&gt; ptrdiff_t memunit_step(const P*);
<span class="lineNum">      39 </span>                : template &lt;typename P&gt; P* memunit_advanced(const P* p, ptrdiff_t diff);
<span class="lineNum">      40 </span>                : template &lt;typename P&gt; P&amp; memunit_advanced_ref(P* p, ptrdiff_t diff);
<span class="lineNum">      41 </span>                : template &lt;typename Iterator, typename D&gt; struct iterator_add_deref;
<span class="lineNum">      42 </span>                : template &lt;typename T&gt; class point2;
<span class="lineNum">      43 </span>                : namespace detail {
<span class="lineNum">      44 </span>                :     // helper class specialized for each axis of pixel_2d_locator
<span class="lineNum">      45 </span>                :     template &lt;std::size_t D, typename Loc&gt;  class locator_axis;
<span class="lineNum">      46 </span>                : }
<span class="lineNum">      47 </span>                : template &lt;typename T&gt; struct dynamic_x_step_type;
<span class="lineNum">      48 </span>                : template &lt;typename T&gt; struct dynamic_y_step_type;
<span class="lineNum">      49 </span>                : 
<span class="lineNum">      50 </span>                : template &lt;typename T&gt; struct channel_type;
<span class="lineNum">      51 </span>                : template &lt;typename T&gt; struct color_space_type;
<span class="lineNum">      52 </span>                : template &lt;typename T&gt; struct channel_mapping_type;
<span class="lineNum">      53 </span>                : template &lt;typename T&gt; struct is_planar;
<span class="lineNum">      54 </span>                : template &lt;typename T&gt; struct num_channels;
<span class="lineNum">      55 </span>                : 
<span class="lineNum">      56 </span>                : // The type of a locator or a view that has X and Y swapped. By default it is the same
<span class="lineNum">      57 </span>                : template &lt;typename T&gt; struct transposed_type {
<span class="lineNum">      58 </span>                :     typedef T type;
<span class="lineNum">      59 </span>                : };
<span class="lineNum">      60 </span>                : 
<span class="lineNum">      61 </span>                : /// \class pixel_2d_locator_base
<span class="lineNum">      62 </span>                : /// \brief base class for models of PixelLocatorConcept
<span class="lineNum">      63 </span>                : /// \ingroup PixelLocatorModel PixelBasedModel
<span class="lineNum">      64 </span>                : ///
<span class="lineNum">      65 </span>                : /// Pixel locator is similar to a pixel iterator, but allows for 2D navigation of pixels within an image view. 
<span class="lineNum">      66 </span>                : /// It has a 2D difference_type and supports random access operations like:
<span class="lineNum">      67 </span>                : /// \code
<span class="lineNum">      68 </span>                : ///     difference_type offset2(2,3);
<span class="lineNum">      69 </span>                : ///     locator+=offset2;
<span class="lineNum">      70 </span>                : ///     locator[offset2]=my_pixel;
<span class="lineNum">      71 </span>                : /// \endcode
<span class="lineNum">      72 </span>                : ///
<span class="lineNum">      73 </span>                : /// In addition, each coordinate acts as a random-access iterator that can be modified separately:
<span class="lineNum">      74 </span>                : /// &quot;++locator.x()&quot; or &quot;locator.y()+=10&quot; thereby moving the locator horizontally or vertically.
<span class="lineNum">      75 </span>                : ///
<span class="lineNum">      76 </span>                : /// It is called a locator because it doesn't implement the complete interface of a random access iterator.
<span class="lineNum">      77 </span>                : /// For example, increment and decrement operations don't make sense (no way to specify dimension).
<span class="lineNum">      78 </span>                : /// Also 2D difference between two locators cannot be computed without knowledge of the X position within the image.
<span class="lineNum">      79 </span>                : /// 
<span class="lineNum">      80 </span>                : /// This base class provides most of the methods and typedefs needed to create a model of a locator. GIL provides two
<span class="lineNum">      81 </span>                : /// locator models as subclasses of \p pixel_2d_locator_base. A memory-based locator, \p memory_based_2d_locator and a virtual
<span class="lineNum">      82 </span>                : /// locator, \p virtual_2d_locator.
<span class="lineNum">      83 </span>                : /// The minimum functionality a subclass must provide is this:
<span class="lineNum">      84 </span>                : /// \code
<span class="lineNum">      85 </span>                : /// class my_locator : public pixel_2d_locator_base&lt;my_locator, ..., ...&gt; {  // supply the types for x-iterator and y-iterator
<span class="lineNum">      86 </span>                : ///        typedef ... const_t;                      // read-only locator
<span class="lineNum">      87 </span>                : ///
<span class="lineNum">      88 </span>                : ///        template &lt;typename Deref&gt; struct add_deref {
<span class="lineNum">      89 </span>                : ///            typedef ... type;                     // locator that invokes the Deref dereference object upon pixel access
<span class="lineNum">      90 </span>                : ///            static type make(const my_locator&amp; loc, const Deref&amp; d);
<span class="lineNum">      91 </span>                : ///        };
<span class="lineNum">      92 </span>                : ///
<span class="lineNum">      93 </span>                : ///        my_locator();
<span class="lineNum">      94 </span>                : ///        my_locator(const my_locator&amp; pl);
<span class="lineNum">      95 </span>                : ///
<span class="lineNum">      96 </span>                : ///        // constructors with dynamic step in y (and x). Only valid for locators with dynamic steps
<span class="lineNum">      97 </span>                : ///        my_locator(const my_locator&amp; loc, coord_t y_step);
<span class="lineNum">      98 </span>                : ///        my_locator(const my_locator&amp; loc, coord_t x_step, coord_t y_step, bool transpose);
<span class="lineNum">      99 </span>                : ///
<span class="lineNum">     100 </span>                : ///        bool              operator==(const my_locator&amp; p) const;
<span class="lineNum">     101 </span>                : ///
<span class="lineNum">     102 </span>                : ///        // return _references_ to horizontal/vertical iterators. Advancing them moves this locator
<span class="lineNum">     103 </span>                : ///        x_iterator&amp;       x();
<span class="lineNum">     104 </span>                : ///        y_iterator&amp;       y();
<span class="lineNum">     105 </span>                : ///        x_iterator const&amp; x() const;
<span class="lineNum">     106 </span>                : ///        y_iterator const&amp; y() const;
<span class="lineNum">     107 </span>                : ///
<span class="lineNum">     108 </span>                : ///        // return the vertical distance to another locator. Some models need the horizontal distance to compute it
<span class="lineNum">     109 </span>                : ///        y_coord_t         y_distance_to(const my_locator&amp; loc2, x_coord_t xDiff) const;
<span class="lineNum">     110 </span>                : ///
<span class="lineNum">     111 </span>                : ///        // return true iff incrementing an x-iterator located at the last column will position it at the first 
<span class="lineNum">     112 </span>                : ///        // column of the next row. Some models need the image width to determine that.
<span class="lineNum">     113 </span>                : ///        bool              is_1d_traversable(x_coord_t width) const;
<span class="lineNum">     114 </span>                : /// };
<span class="lineNum">     115 </span>                : /// \endcode
<span class="lineNum">     116 </span>                : ///
<span class="lineNum">     117 </span>                : /// Models may choose to override some of the functions in the base class with more efficient versions.
<span class="lineNum">     118 </span>                : ///
<span class="lineNum">     119 </span>                : 
<span class="lineNum">     120 </span>                : template &lt;typename Loc, typename XIterator, typename YIterator&gt;    // The concrete subclass, the X-iterator and the Y-iterator
<span class="lineNum">     121 </span><span class="lineCov">            247 : class pixel_2d_locator_base {</span>
<span class="lineNum">     122 </span>                : public:
<span class="lineNum">     123 </span>                :     typedef XIterator           x_iterator;
<span class="lineNum">     124 </span>                :     typedef YIterator           y_iterator;
<span class="lineNum">     125 </span>                : 
<span class="lineNum">     126 </span>                :     // typedefs required by ConstRandomAccessNDLocatorConcept
<span class="lineNum">     127 </span>                :     static const std::size_t num_dimensions=2;
<span class="lineNum">     128 </span>                :     typedef typename std::iterator_traits&lt;x_iterator&gt;::value_type       value_type;
<span class="lineNum">     129 </span>                :     typedef typename std::iterator_traits&lt;x_iterator&gt;::reference        reference;    // result of dereferencing
<span class="lineNum">     130 </span>                :     typedef typename std::iterator_traits&lt;x_iterator&gt;::difference_type  coord_t;      // 1D difference type (same for all dimensions)
<span class="lineNum">     131 </span>                :     typedef point2&lt;coord_t&gt;                                             difference_type; // result of operator-(locator,locator)
<span class="lineNum">     132 </span>                :     typedef difference_type                                             point_t;
<span class="lineNum">     133 </span>                :     template &lt;std::size_t D&gt; struct axis {
<span class="lineNum">     134 </span>                :         typedef typename detail::locator_axis&lt;D,Loc&gt;::coord_t           coord_t;
<span class="lineNum">     135 </span>                :         typedef typename detail::locator_axis&lt;D,Loc&gt;::iterator          iterator;
<span class="lineNum">     136 </span>                :     };
<span class="lineNum">     137 </span>                : 
<span class="lineNum">     138 </span>                : // typedefs required by ConstRandomAccess2DLocatorConcept
<span class="lineNum">     139 </span>                :     typedef typename point_t::template axis&lt;0&gt;::coord_t                 x_coord_t;
<span class="lineNum">     140 </span>                :     typedef typename point_t::template axis&lt;1&gt;::coord_t                 y_coord_t;
<span class="lineNum">     141 </span>                : 
<span class="lineNum">     142 </span>                :     bool              operator!=(const Loc&amp; p)          const { return !(concrete()==p); }
<span class="lineNum">     143 </span>                : 
<span class="lineNum">     144 </span>                :     x_iterator        x_at(x_coord_t dx, y_coord_t dy)  const { Loc tmp=concrete(); tmp+=point_t(dx,dy); return tmp.x(); }
<span class="lineNum">     145 </span>                :     x_iterator        x_at(const difference_type&amp; d)    const { Loc tmp=concrete(); tmp+=d;              return tmp.x(); }
<span class="lineNum">     146 </span>                :     y_iterator        y_at(x_coord_t dx, y_coord_t dy)  const { Loc tmp=concrete(); tmp+=point_t(dx,dy); return tmp.y(); }
<span class="lineNum">     147 </span>                :     y_iterator        y_at(const difference_type&amp; d)    const { Loc tmp=concrete(); tmp+=d;              return tmp.y(); }
<span class="lineNum">     148 </span>                :     Loc               xy_at(x_coord_t dx, y_coord_t dy) const { Loc tmp=concrete(); tmp+=point_t(dx,dy); return tmp; }
<span class="lineNum">     149 </span><span class="lineCov">             52 :     Loc               xy_at(const difference_type&amp; d)   const { Loc tmp=concrete(); tmp+=d;              return tmp; }</span>
<span class="lineNum">     150 </span>                : 
<span class="lineNum">     151 </span>                :     template &lt;std::size_t D&gt; typename axis&lt;D&gt;::iterator&amp;       axis_iterator()                       { return detail::locator_axis&lt;D,Loc&gt;()(concrete()); }
<span class="lineNum">     152 </span>                :     template &lt;std::size_t D&gt; typename axis&lt;D&gt;::iterator const&amp; axis_iterator()                 const { return detail::locator_axis&lt;D,Loc&gt;()(concrete()); }
<span class="lineNum">     153 </span>                :     template &lt;std::size_t D&gt; typename axis&lt;D&gt;::iterator        axis_iterator(const point_t&amp; p) const { return detail::locator_axis&lt;D,Loc&gt;()(concrete(),p); }
<span class="lineNum">     154 </span>                : 
<span class="lineNum">     155 </span>                :     reference         operator()(x_coord_t dx, y_coord_t dy) const { return *x_at(dx,dy); }
<span class="lineNum">     156 </span>                :     reference         operator[](const difference_type&amp; d)   const { return *x_at(d.x,d.y); }
<span class="lineNum">     157 </span>                : 
<span class="lineNum">     158 </span>                :     reference         operator*()                            const { return *concrete().x(); }
<span class="lineNum">     159 </span>                : 
<span class="lineNum">     160 </span>                :     Loc&amp;              operator+=(const difference_type&amp; d)         { concrete().x()+=d.x; concrete().y()+=d.y; return concrete(); }
<span class="lineNum">     161 </span>                :     Loc&amp;              operator-=(const difference_type&amp; d)         { concrete().x()-=d.x; concrete().y()-=d.y; return concrete(); }
<span class="lineNum">     162 </span>                :     
<span class="lineNum">     163 </span><span class="lineCov">             52 :     Loc               operator+(const difference_type&amp; d)    const { return xy_at(d); }</span>
<span class="lineNum">     164 </span>                :     Loc               operator-(const difference_type&amp; d)    const { return xy_at(-d); }
<span class="lineNum">     165 </span>                : 
<span class="lineNum">     166 </span>                :     // Some locators can cache 2D coordinates for faster subsequent access. By default there is no caching
<span class="lineNum">     167 </span>                :     typedef difference_type    cached_location_t;    
<span class="lineNum">     168 </span>                :     cached_location_t cache_location(const difference_type&amp; d)  const { return d; }
<span class="lineNum">     169 </span>                :     cached_location_t cache_location(x_coord_t dx, y_coord_t dy)const { return difference_type(dx,dy); }
<span class="lineNum">     170 </span>                : 
<span class="lineNum">     171 </span>                : private:
<span class="lineNum">     172 </span>                :     Loc&amp;              concrete()       { return (Loc&amp;)*this; }
<span class="lineNum">     173 </span><span class="lineCov">             52 :     const Loc&amp;        concrete() const { return (const Loc&amp;)*this; }</span>
<span class="lineNum">     174 </span>                : 
<span class="lineNum">     175 </span>                :     template &lt;typename X&gt; friend class pixel_2d_locator;
<span class="lineNum">     176 </span>                : };
<span class="lineNum">     177 </span>                : 
<span class="lineNum">     178 </span>                : // helper classes for each axis of pixel_2d_locator_base
<span class="lineNum">     179 </span>                : namespace detail {
<span class="lineNum">     180 </span>                :     template &lt;typename Loc&gt; 
<span class="lineNum">     181 </span>                :     class locator_axis&lt;0,Loc&gt; {
<span class="lineNum">     182 </span>                :         typedef typename Loc::point_t                       point_t;
<span class="lineNum">     183 </span>                :     public:
<span class="lineNum">     184 </span>                :         typedef typename point_t::template axis&lt;0&gt;::coord_t coord_t;
<span class="lineNum">     185 </span>                :         typedef typename Loc::x_iterator                    iterator;
<span class="lineNum">     186 </span>                : 
<span class="lineNum">     187 </span>                :         inline iterator&amp;        operator()(      Loc&amp; loc)                   const { return loc.x(); }
<span class="lineNum">     188 </span>                :         inline iterator  const&amp; operator()(const Loc&amp; loc)                   const { return loc.x(); }
<span class="lineNum">     189 </span>                :         inline iterator         operator()(      Loc&amp; loc, const point_t&amp; d) const { return loc.x_at(d); }
<span class="lineNum">     190 </span>                :         inline iterator         operator()(const Loc&amp; loc, const point_t&amp; d) const { return loc.x_at(d); }
<span class="lineNum">     191 </span>                :     };
<span class="lineNum">     192 </span>                : 
<span class="lineNum">     193 </span>                :     template &lt;typename Loc&gt; 
<span class="lineNum">     194 </span>                :     class locator_axis&lt;1,Loc&gt; {
<span class="lineNum">     195 </span>                :         typedef typename Loc::point_t                       point_t;
<span class="lineNum">     196 </span>                :     public:
<span class="lineNum">     197 </span>                :         typedef typename point_t::template axis&lt;1&gt;::coord_t coord_t;
<span class="lineNum">     198 </span>                :         typedef typename Loc::y_iterator                    iterator;
<span class="lineNum">     199 </span>                : 
<span class="lineNum">     200 </span>                :         inline iterator&amp;        operator()(      Loc&amp; loc)               const { return loc.y(); }
<span class="lineNum">     201 </span>                :         inline iterator const&amp;  operator()(const Loc&amp; loc)               const { return loc.y(); }
<span class="lineNum">     202 </span>                :         inline iterator     operator()(      Loc&amp; loc, const point_t&amp; d) const { return loc.y_at(d); }
<span class="lineNum">     203 </span>                :         inline iterator     operator()(const Loc&amp; loc, const point_t&amp; d) const { return loc.y_at(d); }
<span class="lineNum">     204 </span>                :     };
<span class="lineNum">     205 </span>                : }
<span class="lineNum">     206 </span>                : 
<span class="lineNum">     207 </span>                : template &lt;typename Loc, typename XIt, typename YIt&gt;
<span class="lineNum">     208 </span>                : struct channel_type&lt;pixel_2d_locator_base&lt;Loc,XIt,YIt&gt; &gt; : public channel_type&lt;XIt&gt; {};
<span class="lineNum">     209 </span>                : 
<span class="lineNum">     210 </span>                : template &lt;typename Loc, typename XIt, typename YIt&gt;
<span class="lineNum">     211 </span>                : struct color_space_type&lt;pixel_2d_locator_base&lt;Loc,XIt,YIt&gt; &gt; : public color_space_type&lt;XIt&gt; {};
<span class="lineNum">     212 </span>                : 
<span class="lineNum">     213 </span>                : template &lt;typename Loc, typename XIt, typename YIt&gt;
<span class="lineNum">     214 </span>                : struct channel_mapping_type&lt;pixel_2d_locator_base&lt;Loc,XIt,YIt&gt; &gt; : public channel_mapping_type&lt;XIt&gt; {};
<span class="lineNum">     215 </span>                : 
<span class="lineNum">     216 </span>                : template &lt;typename Loc, typename XIt, typename YIt&gt;
<span class="lineNum">     217 </span>                : struct is_planar&lt;pixel_2d_locator_base&lt;Loc,XIt,YIt&gt; &gt; : public is_planar&lt;XIt&gt; {};
<span class="lineNum">     218 </span>                : 
<span class="lineNum">     219 </span>                : /// \class memory_based_2d_locator
<span class="lineNum">     220 </span>                : /// \brief Memory-based pixel locator. Models: PixelLocatorConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept
<span class="lineNum">     221 </span>                : /// \ingroup PixelLocatorModel PixelBasedModel
<span class="lineNum">     222 </span>                : ///
<span class="lineNum">     223 </span>                : /// The class takes a step iterator as a parameter. The step iterator provides navigation along the vertical axis
<span class="lineNum">     224 </span>                : /// while its base iterator provides horizontal navigation.
<span class="lineNum">     225 </span>                : ///
<span class="lineNum">     226 </span>                : /// Each instantiation is optimal in terms of size and efficiency.
<span class="lineNum">     227 </span>                : /// For example, xy locator over interleaved rgb image results in a step iterator consisting of 
<span class="lineNum">     228 </span>                : /// one std::ptrdiff_t for the row size and one native pointer (8 bytes total). ++locator.x() resolves to pointer 
<span class="lineNum">     229 </span>                : /// increment. At the other extreme, a 2D navigation of the even pixels of a planar CMYK image results in a step 
<span class="lineNum">     230 </span>                : /// iterator consisting of one std::ptrdiff_t for the doubled row size, and one step iterator consisting of 
<span class="lineNum">     231 </span>                : /// one std::ptrdiff_t for the horizontal step of two and a CMYK planar_pixel_iterator consisting of 4 pointers (24 bytes).
<span class="lineNum">     232 </span>                : /// In this case ++locator.x() results in four native pointer additions.
<span class="lineNum">     233 </span>                : ///
<span class="lineNum">     234 </span>                : /// Note also that \p memory_based_2d_locator does not require that its element type be a pixel. It could be
<span class="lineNum">     235 </span>                : /// instantiated with an iterator whose \p value_type models only \p Regular. In this case the locator
<span class="lineNum">     236 </span>                : /// models the weaker RandomAccess2DLocatorConcept, and does not model PixelBasedConcept.
<span class="lineNum">     237 </span>                : /// Many generic algorithms don't require the elements to be pixels.
<span class="lineNum">     238 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">     239 </span>                : 
<span class="lineNum">     240 </span>                : template &lt;typename StepIterator&gt;
<span class="lineNum">     241 </span>                : class memory_based_2d_locator : public pixel_2d_locator_base&lt;memory_based_2d_locator&lt;StepIterator&gt;, typename iterator_adaptor_get_base&lt;StepIterator&gt;::type, StepIterator&gt; {
<span class="lineNum">     242 </span>                :     typedef memory_based_2d_locator&lt;StepIterator&gt;  this_t;
<span class="lineNum">     243 </span>                :     GIL_CLASS_REQUIRE(StepIterator, boost::gil, StepIteratorConcept)
<span class="lineNum">     244 </span>                : public:
<span class="lineNum">     245 </span>                :     typedef pixel_2d_locator_base&lt;memory_based_2d_locator&lt;StepIterator&gt;, typename iterator_adaptor_get_base&lt;StepIterator&gt;::type, StepIterator&gt; parent_t;
<span class="lineNum">     246 </span>                :     typedef memory_based_2d_locator&lt;typename const_iterator_type&lt;StepIterator&gt;::type&gt; const_t; // same as this type, but over const values
<span class="lineNum">     247 </span>                : 
<span class="lineNum">     248 </span>                :     typedef typename parent_t::coord_t          coord_t;
<span class="lineNum">     249 </span>                :     typedef typename parent_t::x_coord_t        x_coord_t;
<span class="lineNum">     250 </span>                :     typedef typename parent_t::y_coord_t        y_coord_t;
<span class="lineNum">     251 </span>                :     typedef typename parent_t::x_iterator       x_iterator;
<span class="lineNum">     252 </span>                :     typedef typename parent_t::y_iterator       y_iterator;
<span class="lineNum">     253 </span>                :     typedef typename parent_t::difference_type  difference_type;
<span class="lineNum">     254 </span>                :     typedef typename parent_t::reference        reference;
<span class="lineNum">     255 </span>                : 
<span class="lineNum">     256 </span>                :     template &lt;typename Deref&gt; struct add_deref {
<span class="lineNum">     257 </span>                :         typedef memory_based_2d_locator&lt;typename iterator_add_deref&lt;StepIterator,Deref&gt;::type&gt; type;
<span class="lineNum">     258 </span>                :         static type make(const memory_based_2d_locator&lt;StepIterator&gt;&amp; loc, const Deref&amp; nderef) { 
<span class="lineNum">     259 </span>                :             return type(iterator_add_deref&lt;StepIterator,Deref&gt;::make(loc.y(),nderef)); 
<span class="lineNum">     260 </span>                :         }
<span class="lineNum">     261 </span>                :     };
<span class="lineNum">     262 </span>                : 
<span class="lineNum">     263 </span><span class="lineCov">             47 :     memory_based_2d_locator() {}</span>
<span class="lineNum">     264 </span>                :     memory_based_2d_locator(const StepIterator&amp; yit) : _p(yit) {}
<span class="lineNum">     265 </span><span class="lineCov">              4 :     template &lt;typename SI&gt; memory_based_2d_locator(const memory_based_2d_locator&lt;SI&gt;&amp; loc, coord_t y_step) : _p(loc.x(), loc.row_size()*y_step) {}</span>
<span class="lineNum">     266 </span><span class="lineCov">             45 :     template &lt;typename SI&gt; memory_based_2d_locator(const memory_based_2d_locator&lt;SI&gt;&amp; loc, coord_t x_step, coord_t y_step, bool transpose=false)</span>
<span class="lineNum">     267 </span>                :         : _p(make_step_iterator(loc.x(),(transpose ? loc.row_size() : loc.pixel_size())*x_step),
<span class="lineNum">     268 </span><span class="lineCov">             45 :                                         (transpose ? loc.pixel_size() : loc.row_size())*y_step ) {}</span>
<span class="lineNum">     269 </span>                : 
<span class="lineNum">     270 </span><span class="lineCov">              7 :     memory_based_2d_locator(x_iterator xit, std::ptrdiff_t row_bytes) : _p(xit,row_bytes) {}</span>
<span class="lineNum">     271 </span>                :     template &lt;typename X&gt; memory_based_2d_locator(const memory_based_2d_locator&lt;X&gt;&amp; pl) : _p(pl._p) {}
<span class="lineNum">     272 </span><span class="lineCov">            165 :     memory_based_2d_locator(const memory_based_2d_locator&amp; pl) : _p(pl._p) {}</span>
<span class="lineNum">     273 </span>                : 
<span class="lineNum">     274 </span><span class="lineCov">             12 :     bool                  operator==(const this_t&amp; p)  const { return _p==p._p; }</span>
<span class="lineNum">     275 </span>                : 
<span class="lineNum">     276 </span><span class="lineCov">           1155 :     x_iterator const&amp;     x()                          const { return _p.base(); }</span>
<span class="lineNum">     277 </span><span class="lineCov">            609 :     y_iterator const&amp;     y()                          const { return _p; }</span>
<span class="lineNum">     278 </span><span class="lineCov">             58 :     x_iterator&amp;           x()                                { return _p.base(); }</span>
<span class="lineNum">     279 </span>                :     y_iterator&amp;           y()                                { return _p; }
<span class="lineNum">     280 </span>                : 
<span class="lineNum">     281 </span>                :     // These are faster versions of functions already provided in the superclass 
<span class="lineNum">     282 </span><span class="lineCov">            516 :     x_iterator x_at      (x_coord_t dx, y_coord_t dy)  const { return memunit_advanced(x(), offset(dx,dy)); }    </span>
<span class="lineNum">     283 </span>                :     x_iterator x_at      (const difference_type&amp; d)    const { return memunit_advanced(x(), offset(d.x,d.y)); }
<span class="lineNum">     284 </span>                :     this_t     xy_at     (x_coord_t dx, y_coord_t dy)  const { return this_t(x_at( dx , dy ), row_size()); }
<span class="lineNum">     285 </span>                :     this_t     xy_at     (const difference_type&amp; d)    const { return this_t(x_at( d.x, d.y), row_size()); }
<span class="lineNum">     286 </span><span class="lineNoCov">              0 :     reference  operator()(x_coord_t dx, y_coord_t dy)  const { return memunit_advanced_ref(x(),offset(dx,dy)); }</span>
<span class="lineNum">     287 </span>                :     reference  operator[](const difference_type&amp; d)    const { return memunit_advanced_ref(x(),offset(d.x,d.y)); }
<span class="lineNum">     288 </span><span class="lineCov">             44 :     this_t&amp;    operator+=(const difference_type&amp; d)          { memunit_advance(x(),offset(d.x,d.y)); return *this; }</span>
<span class="lineNum">     289 </span>                :     this_t&amp;    operator-=(const difference_type&amp; d)          { memunit_advance(x(),offset(-d.x,-d.y)); return *this; }
<span class="lineNum">     290 </span>                : 
<span class="lineNum">     291 </span>                :     // Memory-based locators can have 1D caching of 2D relative coordinates
<span class="lineNum">     292 </span>                :     typedef std::ptrdiff_t cached_location_t; // type used to store relative location (to allow for more efficient repeated access)
<span class="lineNum">     293 </span>                :     cached_location_t cache_location(const difference_type&amp; d)  const { return offset(d.x,d.y); }
<span class="lineNum">     294 </span>                :     cached_location_t cache_location(x_coord_t dx, y_coord_t dy)const { return offset(dx,dy); }
<span class="lineNum">     295 </span>                :     reference         operator[](const cached_location_t&amp; loc)  const { return memunit_advanced_ref(x(),loc); }
<span class="lineNum">     296 </span>                : 
<span class="lineNum">     297 </span>                :     // Only make sense for memory-based locators
<span class="lineNum">     298 </span><span class="lineCov">            609 :     std::ptrdiff_t         row_size()                           const { return memunit_step(y()); }    // distance in mem units (bytes or bits) between adjacent rows</span>
<span class="lineNum">     299 </span><span class="lineCov">            605 :     std::ptrdiff_t         pixel_size()                         const { return memunit_step(x()); }    // distance in mem units (bytes or bits) between adjacent pixels on the same row</span>
<span class="lineNum">     300 </span>                : 
<span class="lineNum">     301 </span><span class="lineCov">             15 :     bool                   is_1d_traversable(x_coord_t width)   const { return row_size()-pixel_size()*width==0; }   // is there no gap at the end of each row?</span>
<span class="lineNum">     302 </span>                : 
<span class="lineNum">     303 </span>                :     // Returns the vertical distance (it2.y-it1.y) between two x_iterators given the difference of their x positions
<span class="lineNum">     304 </span>                :     std::ptrdiff_t y_distance_to(const this_t&amp; p2, x_coord_t xDiff) const { 
<span class="lineNum">     305 </span>                :         std::ptrdiff_t rowDiff=memunit_distance(x(),p2.x())-pixel_size()*xDiff;
<span class="lineNum">     306 </span>                :         assert(( rowDiff % row_size())==0);
<span class="lineNum">     307 </span>                :         return rowDiff / row_size();
<span class="lineNum">     308 </span>                :     }
<span class="lineNum">     309 </span>                : 
<span class="lineNum">     310 </span>                : private:
<span class="lineNum">     311 </span>                :     template &lt;typename X&gt; friend class memory_based_2d_locator;
<span class="lineNum">     312 </span><span class="lineCov">            560 :     std::ptrdiff_t offset(x_coord_t x, y_coord_t y)        const { return y*row_size() + x*pixel_size(); }</span>
<span class="lineNum">     313 </span>                :     StepIterator _p;
<span class="lineNum">     314 </span>                : };
<span class="lineNum">     315 </span>                : 
<span class="lineNum">     316 </span>                : /////////////////////////////
<span class="lineNum">     317 </span>                : //  PixelBasedConcept
<span class="lineNum">     318 </span>                : /////////////////////////////
<span class="lineNum">     319 </span>                : 
<span class="lineNum">     320 </span>                : template &lt;typename SI&gt;
<span class="lineNum">     321 </span>                : struct color_space_type&lt;memory_based_2d_locator&lt;SI&gt; &gt; : public color_space_type&lt;typename memory_based_2d_locator&lt;SI&gt;::parent_t&gt; {
<span class="lineNum">     322 </span>                : };
<span class="lineNum">     323 </span>                : 
<span class="lineNum">     324 </span>                : template &lt;typename SI&gt;
<span class="lineNum">     325 </span>                : struct channel_mapping_type&lt;memory_based_2d_locator&lt;SI&gt; &gt; : public channel_mapping_type&lt;typename memory_based_2d_locator&lt;SI&gt;::parent_t&gt; {
<span class="lineNum">     326 </span>                : };
<span class="lineNum">     327 </span>                : 
<span class="lineNum">     328 </span>                : template &lt;typename SI&gt;
<span class="lineNum">     329 </span>                : struct is_planar&lt;memory_based_2d_locator&lt;SI&gt; &gt; : public is_planar&lt;typename memory_based_2d_locator&lt;SI&gt;::parent_t&gt; {
<span class="lineNum">     330 </span>                : };
<span class="lineNum">     331 </span>                : 
<span class="lineNum">     332 </span>                : template &lt;typename SI&gt;
<span class="lineNum">     333 </span>                : struct channel_type&lt;memory_based_2d_locator&lt;SI&gt; &gt; : public channel_type&lt;typename memory_based_2d_locator&lt;SI&gt;::parent_t&gt; {
<span class="lineNum">     334 </span>                : };
<span class="lineNum">     335 </span>                : 
<span class="lineNum">     336 </span>                : /////////////////////////////
<span class="lineNum">     337 </span>                : //  HasDynamicXStepTypeConcept
<span class="lineNum">     338 </span>                : /////////////////////////////
<span class="lineNum">     339 </span>                : 
<span class="lineNum">     340 </span>                : // Take the base iterator of SI (which is typically a step iterator) and change it to have a step in x
<span class="lineNum">     341 </span>                : template &lt;typename SI&gt;
<span class="lineNum">     342 </span>                : struct dynamic_x_step_type&lt;memory_based_2d_locator&lt;SI&gt; &gt; {
<span class="lineNum">     343 </span>                : private:
<span class="lineNum">     344 </span>                :     typedef typename iterator_adaptor_get_base&lt;SI&gt;::type                        base_iterator_t;
<span class="lineNum">     345 </span>                :     typedef typename dynamic_x_step_type&lt;base_iterator_t&gt;::type                 base_iterator_step_t;
<span class="lineNum">     346 </span>                :     typedef typename iterator_adaptor_rebind&lt;SI, base_iterator_step_t&gt;::type    dynamic_step_base_t;
<span class="lineNum">     347 </span>                : public:
<span class="lineNum">     348 </span>                :     typedef memory_based_2d_locator&lt;dynamic_step_base_t&gt; type;
<span class="lineNum">     349 </span>                : };
<span class="lineNum">     350 </span>                : 
<span class="lineNum">     351 </span>                : /////////////////////////////
<span class="lineNum">     352 </span>                : //  HasDynamicYStepTypeConcept
<span class="lineNum">     353 </span>                : /////////////////////////////
<span class="lineNum">     354 </span>                : 
<span class="lineNum">     355 </span>                : template &lt;typename SI&gt;
<span class="lineNum">     356 </span>                : struct dynamic_y_step_type&lt;memory_based_2d_locator&lt;SI&gt; &gt; {
<span class="lineNum">     357 </span>                :     typedef memory_based_2d_locator&lt;SI&gt; type;
<span class="lineNum">     358 </span>                : };
<span class="lineNum">     359 </span>                : 
<span class="lineNum">     360 </span>                : } }  // namespace boost::gil
<span class="lineNum">     361 </span>                : 
<span class="lineNum">     362 </span>                : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
